import unittest
import util
import random

class UtilTest(unittest.TestCase):
    """Test case for the 'util' module"""
    def setUp(self):
        "setup goes here"
    
    def test_color_spectrum(self):
        "Test the ColorSpectrum class"
        
        #test default low/high
        cs = util.ColorSpectrum()
        self.assertEquals(cs.low, 0)
        self.assertEquals(cs.high, 100)
        self.assertEquals(cs.invert, False)
        
        self.assertEquals((0, 255, 0), cs.get_color(0))
        self.assertEquals((0, 255, 0), cs.get_color(-50))
        self.assertEquals((255, 0, 0), cs.get_color(100))
        self.assertEquals((255, 0, 0), cs.get_color(150))
        
        color = cs.get_color(25)
        self.assertTrue(color[0] > 0)
        self.assertTrue(color[0] < 255)
        self.assertEquals(color[1], 255)
        self.assertEquals(color[2], 0)
        
        color = cs.get_color(75)
        self.assertEquals(color[0], 255)
        self.assertTrue(color[1] > 0)
        self.assertTrue(color[1] < 255)
        self.assertEquals(color[2], 0)
        
        for i in range(50):
            value = int(random.uniform(0, 100))
            color = cs.get_color(value)
            self.assertTrue(color[0] == 255 or color[1] == 255)
        
        
        cs = util.ColorSpectrum(invert = True)
        self.assertEquals(cs.low, 0)
        self.assertEquals(cs.high, 100)
        self.assertEquals(cs.invert, True)
        
        self.assertEquals((255, 0, 0), cs.get_color(0))
        self.assertEquals((255, 0, 0), cs.get_color(-50))
        self.assertEquals((0, 255, 0), cs.get_color(100))
        self.assertEquals((0, 255, 0), cs.get_color(150))
        
        color = cs.get_color(75)
        self.assertTrue(color[0] > 0)
        self.assertTrue(color[0] < 255)
        self.assertEquals(color[1], 255)
        self.assertEquals(color[2], 0)
        
        color = cs.get_color(25)
        self.assertEquals(color[0], 255)
        self.assertTrue(color[1] > 0)
        self.assertTrue(color[1] < 255)
        self.assertEquals(color[2], 0)
        
        for i in range(50):
            value = int(random.uniform(0, 100))
            color = cs.get_color(value)
            self.assertTrue(color[0] == 255 or color[1] == 255)
        
        
        #test custom low/high
            #TODO
    


if __name__ == '__main__':
    unittest.main()
    
def get_suite():
    return unittest.makeSuite(UtilTest)
